<template>
  <el-dialog
    title="dialogtype==0?'添加':'修改"
    :visible.sync="dialogVisible"
    width="30%"
    :before-close="handleClose"
  >
    <el-form
      :model="dialoForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
    >
      <el-form-item label="姓名" prop="username">
        <el-input v-model="dialoForm.username"></el-input>
      </el-form-item>
      <el-form-item label="就诊卡号" prop="jiuka">
        <el-input v-model="dialoForm.jiuka"></el-input>
      </el-form-item>
      <el-form-item label="身份证号" prop="card">
        <el-input v-model="dialoForm.card"></el-input>
      </el-form-item>
      <el-form-item label="手机号码" prop="number">
        <el-input v-model="dialoForm.number"></el-input>
      </el-form-item>
      <el-form-item label="科室" prop="dwork">
        <el-input v-model="dialoForm.dwork"></el-input>
      </el-form-item>
      <el-form-item label="检测费" prop="testfee">
        <el-input v-model="dialoForm.testfee"></el-input>
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-input v-model="dialoForm.state"></el-input>
      </el-form-item>
      <el-form-item label="就诊日期" prop="date">
        <el-input v-model="dialoForm.date"></el-input>
      </el-form-item>
      <el-form-item label="候诊时间" prop="date">
        <el-input v-model="dialoForm.date"></el-input>
      </el-form-item>
      <el-form-item label="预约时间" prop="date">
        <el-input v-model="dialoForm.date"></el-input>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { AddhomeApi, updateApi } from "../../../api/na";

export default {
  props: ["dialogrow", "dialogtype"],
  data() {
    return {
      dialogVisible: true,
      dialoForm: {
        id: "",
        username: "",
        jiuka: "",
        card: "",
        number: "",
        dwork: "",
        testfee: "",
        state: "",
        date: "",
        time: "",
      },
      rules: {
        username: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        jiuka: [{ required: true, message: "请输入就诊卡号", trigger: "blur" }],
        card: [{ required: true, message: "请输入身份证号", trigger: "blur" }],
        number: [
          { required: true, message: "请输入手机号码", trigger: "blur" },
        ],
        dwork: [{ required: true, message: "请输入科室", trigger: "blur" }],
        testfee: [{ required: true, message: "请输入检测费", trigger: "blur" }],
        state: [{ required: true, message: "请输入状态", trigger: "blur" }],
        date: [{ required: true, message: "请输入就诊时间", trigger: "blur" }],
      },
    };
  },
  mounted() {
    this.dialoForm = { ...this.dialogrow };
  },
  methods: {
    submitForm() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          if (this.dialogtype == 0) {
            AddhomeApi(this.dialoForm).then((res) => {
              console.log("res", res);
              if (res.code == 200) {
                this.$emit("addTable");
              }
            });
          } else if (this.dialogtype == 1) {
            updateApi(this.dialoForm).then((res) => {
                console.log(res);
                if (res.code == 200) {
                this.$emit("addTable");
              }
            });
          }
        } else {
          console.log("不通过!!");
          return false;
        }
      });
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
          this.$emit("closeDialog");
        })
        .catch((_) => {});
    },
    closeDialog() {
      this.$emit("closeDialog");
    },
  },
};
</script>
<style>
</style>